// pages/记录/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // url
    toDailyInfo: '1',
    toPetSick: '1',
    toPetVaccination:'1',
    havePet:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
// 用户宠物数据
    wx.request({
      url: app.globalData.prefixUrl + '/chong/pet/pet/user/' + app.globalData.userId,
      method:"GET",
      success(e){
        console.log("获取当前用户宠物数据成功: ",e)
        if (e.data == null || e.data == '') {
          console.log("用户没有宠物")
        } else {
          that.setData({
            toDailyInfo: '../daily/index',
            toPetSick: '../petSick/index',
            toPetVaccination: '../petVaccination/index',
            havePet:true,
          })
        }
      },
      fail(e){
        console.log("获取当前用户宠物数据失败: ",e)
      }
    })  
  },
  
  showMessage(){
    var that = this
    if(!that.data.havePet) {
      wx.showToast({
        title: '请先添加宠物',
        icon: 'none',
        duration: 2000,
      })
    }
  },
})